package logic

import (
	"context"
	"library/models/mysql"

	"library/libraryrpc/internal/svc"
	"library/libraryrpc/libraryrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LabelListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLabelListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LabelListLogic {
	return &LabelListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LabelListLogic) LabelList(in *libraryrpc.LabelListRequest) (*libraryrpc.LabelListResponse, error) {
	// todo: add your logic here and delete this line

	var labels []mysql.Label
	mysql.DB.Find(&labels)
	var labelList []*libraryrpc.LabelList
	for _, label := range labels {
		list := libraryrpc.LabelList{
			UserId:        int64(label.UserId),
			InformationId: int64(label.InformationId),
			Name:          label.Name,
			Content:       label.Content,
			LabelId:       int64(label.ID),
		}
		labelList = append(labelList, &list)
	}
	return &libraryrpc.LabelListResponse{
		List: labelList,
	}, nil
}
